#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    vector<vector<int>> queensAttacktheKing(vector<vector<int>> &queens, vector<int> &king)
    {
        vector<vector<int>> ret;

        unordered_set<int> ques;
        for (auto &que : queens)
        {
            ques.insert(que[0] * 8 + que[1]);
        }

        // 右边
        for (int i = king[0] + 1; i < 8; i++)
        {
            if (ques.count(i * 8 + king[1]))
            {
                ret.push_back({i, king[1]});
                break;
            }
        }
        // 上边
        for (int i = king[1] - 1; i >= 0; i--)
        {
            if (ques.count(king[0] * 8 + i))
            {
                ret.push_back({king[0], i});
                break;
            }
        }
        // 下边
        for (int i = king[1] + 1; i < 8; i++)
        {
            if (ques.count(king[0] * 8 + i))
            {

                ret.push_back({king[0], i});
                break;
            }
        }
        // 左边
        for (int i = king[0] - 1; i >= 0; i--)
        {
            if (ques.count(i * 8 + king[1]))
            {
                ret.push_back({i, king[1]});
                break;
            }
        }
        // 左上对角线
        for (int i = king[0] - 1, j = king[1] - 1; i >= 0 && j >= 0; j--, i--)
        {
            if (ques.count(i * 8 + j))
            {
                ret.push_back({i, j});
                break;
            }
        }
        // 右上对角线
        for (int i = king[0] - 1, j = king[1] + 1; i >= 0 && j < 8; j++, i--)
        {
            if (ques.count(i * 8 + j))
            {
                ret.push_back({i, j});
                break;
            }
        }
        // 左下对角线
        for (int i = king[0] + 1, j = king[1] - 1; i < 8 && j >= 0; j--, i++)
        {
            if (ques.count(i * 8 + j))
            {
                ret.push_back({i, j});
                break;
            }
        }
        // 右下对角线
        for (int i = king[0] + 1, j = king[1] + 1; i < 8 && j < 8; j++, i++)
        {
            if (ques.count(i * 8 + j))
            {
                ret.push_back({i, j});
                break;
            }
        }
        return ret;
    }
};